/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tmp.ac.engin.setting;

import tmp.ac.lib.tools.DBClass;
import tmp.ac.lib.tools.uiUtil;
import tmp.ac.options.DataModel;

/**
 *
 * @author ismail
 */
public class usersSetting extends tmp.ac.engin.gen.genOprtions {

    DBClass db = new DBClass();

    public usersSetting() {

        super(
                tmp.ac.options.DataModel.USERES_TABLE,
                new String[]{"userName", "password", "lang", "per"});

    }

    public boolean IsCan(String Type) {
        boolean retData = false;
        String[] rData = this.getPer("can");
        for (int i = 0; i < rData.length; i++) {
            if (rData[i].equalsIgnoreCase(Type)) {

                retData = true;
            }
        }
        return retData;
    }

    public boolean IsView(String Type) {
        boolean retData = false;
        String[] rData = this.getPer("view");
        for (int i = 0; i < rData.length; i++) {
            if (rData[i].equalsIgnoreCase(Type)) {

                retData = true;
            }
        }
        return retData;
    }

    private String[] getPer(String type) {
        String[] retDataa = null;
   //     String id = TMP.ac.acpcland.sesstionData.userID;


  //      String[] userData = db.getRow(tmp.ac.options.DataModel.USERES_TABLE, Integer.parseInt(id));

    //    String[] perData = db.getRow(tmp.ac.options.DataModel.PERMISSIONS_TABLE, Integer.parseInt(userData[4]));


        if (type.equalsIgnoreCase("view")) {
           
      //      retDataa = perData[3].split(";");
        } else {
  //          retDataa = perData[2].split(";");
//

        }



        return retDataa;
    }

    public void getView(String id) {
    }

    public boolean LogIn(String userName, String password) {
        boolean returnData = false;
        TMP.ac.acpcland.sesstionData.userID = "";

        String[] sqlData = db.getRow(DataModel.USERES_TABLE, "`userName`='" + userName + "' and `password`='" + tmp.ac.lib.tools.util.md5(password) + "'");

        if (sqlData[0] != null && !sqlData.equals("null")) {

            returnData = true;
            TMP.ac.acpcland.sesstionData.userID = sqlData[0];


        }
        //   uiUtil.sendMessage(null, "" + returnData, ac.acpcland.sesstionData.userID);
        return returnData;

    }
}
